package com.iwomy.envpro.platform.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iwomy.envpro.common.core.util.R;
import com.iwomy.envpro.common.log.annotation.SysLog;
import com.iwomy.envpro.platform.entity.BasicCustomLogoEntity;
import com.iwomy.envpro.platform.service.BasicCustomLogoService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.iwomy.envpro.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 基础信息-自定义LOGO
 *
 * @author pig
 * @date 2023-09-23 15:45:50
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/basicCustomLogo")
@Tag(description = "basicCustomLogo", name = "基础信息-自定义LOGO管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class BasicCustomLogoController {

	private final BasicCustomLogoService basicCustomLogoService;

	/**
	 * 分页查询
	 *
	 * @param page            分页对象
	 * @param basicCustomLogo 基础信息-自定义LOGO
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('platform_basicCustomLogo_view')")
	public R getBasicCustomLogoPage(@ParameterObject Page page, @ParameterObject BasicCustomLogoEntity basicCustomLogo) {
		LambdaQueryWrapper<BasicCustomLogoEntity> wrapper = Wrappers.lambdaQuery(basicCustomLogo);
		return R.ok(basicCustomLogoService.page(page, wrapper));
	}


	/**
	 * 通过id查询基础信息-自定义LOGO
	 *
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("")
	@PreAuthorize("@pms.hasPermission('platform_basicCustomLogo_view')")
	public R getById() {
		return R.ok(basicCustomLogoService.getOne(Wrappers.query()));
	}

	/**
	 * 新增基础信息-自定义LOGO
	 *
	 * @param basicCustomLogo 基础信息-自定义LOGO
	 * @return R
	 */
	@Operation(summary = "新增基础信息-自定义LOGO", description = "新增基础信息-自定义LOGO")
	@SysLog("新增基础信息-自定义LOGO")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('platform_basicCustomLogo_add')")
	public R save(@RequestBody BasicCustomLogoEntity basicCustomLogo) {
		BasicCustomLogoEntity basicCustomLogoEntity = basicCustomLogoService.getOne(Wrappers.query());
		if (ObjectUtil.isNotNull(basicCustomLogoEntity))
			basicCustomLogoService.removeById(basicCustomLogoEntity);
		return R.ok(basicCustomLogoService.save(basicCustomLogo));
	}

	/**
	 * 修改基础信息-自定义LOGO
	 *
	 * @param basicCustomLogo 基础信息-自定义LOGO
	 * @return R
	 */
	@Operation(summary = "修改基础信息-自定义LOGO", description = "修改基础信息-自定义LOGO")
	@SysLog("修改基础信息-自定义LOGO")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('platform_basicCustomLogo_edit')")
	public R updateById(@RequestBody BasicCustomLogoEntity basicCustomLogo) {
		return R.ok(basicCustomLogoService.updateById(basicCustomLogo));
	}

	/**
	 * 通过id删除基础信息-自定义LOGO
	 *
	 * @param ids id列表
	 * @return R
	 */
	@Operation(summary = "通过id删除基础信息-自定义LOGO", description = "通过id删除基础信息-自定义LOGO")
	@SysLog("通过id删除基础信息-自定义LOGO")
	@DeleteMapping
	@PreAuthorize("@pms.hasPermission('platform_basicCustomLogo_del')")
	public R removeById(@RequestBody Long[] ids) {
		return R.ok(basicCustomLogoService.removeBatchByIds(CollUtil.toList(ids)));
	}


	/**
	 * 导出excel 表格
	 *
	 * @param basicCustomLogo 查询条件
	 * @return excel 文件流
	 */
	@ResponseExcel
	@GetMapping("/export")
	@PreAuthorize("@pms.hasPermission('platform_basicCustomLogo_export')")
	public List<BasicCustomLogoEntity> export(BasicCustomLogoEntity basicCustomLogo) {
		return basicCustomLogoService.list(Wrappers.query(basicCustomLogo));
	}

/*************************app接口**********************************/
	/**
	 * 通过id查询基础信息-自定义LOGO
	 *
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("appGetById")
	public R appGetById() {
		return R.ok(basicCustomLogoService.getOne(Wrappers.query()));
	}
}